import { Action, ActionReducer } from '@ngrx/store';
import { AuthActions } from '../actions/auth.actions';
import { AuthState, AuthStateRecord } from './auth.state';
// import {CustomAction} from '../actions/base.actions';

export const initialState: AuthState = new AuthStateRecord() as AuthState;


export function authReducer(state : AuthState = initialState, action: Action) {
  console.log('auth reducer..');
  switch ( action.type) {
    case AuthActions.LOGIN_SUCCESS:
      return state.merge({ isAuthenticated: true }) as AuthState;

    case AuthActions.LOGOUT_SUCCESS:
      return state.merge({ isAuthenticated: false }) as AuthState;

    default:
      return state;
  }
}

// export const authReducer: ActionReducer<AuthState> =
//   (state: AuthState = initialState, { type }: Action): AuthState => {
//     console.log('auth reducer..');
//     switch (type) {
//       case AuthActions.LOGIN_SUCCESS:
//         return state.merge({ isAuthenticated: true }) as AuthState;

//       case AuthActions.LOGOUT_SUCCESS:
//         return state.merge({ isAuthenticated: false }) as AuthState;

//       default:
//         return state;
//     }
//   };
